import request from '../utils/request'

/**
 * 登录
 * @param user 
 * @returns 
 */
export const login = user =>{
    return request({
        url:'/sessions',
        method:'POST',
        data:user
    })
}
/**
 * 医生个人信息
 * @param id 
 * @returns 
 */
export const userMessage = (condition = {}) =>{
    return request({
        url:'/doctors',
        method:'GET',
        params:condition
    })
 }

 /**
 * 修改会员信息
 * @param {*} user 
 * @returns 
 */
export const updateUser = user =>{
    console.log('user:', user);
    const formData = new FormData()
    Object.keys(user).forEach(key => {
        if (user[key]) {
            formData.append(key, user[key])
        }
    })
    return request({
        url:'/doctors' + '/' + user.id,
        method:'POST',
        data: formData,
    })
}


export const updateUserPwd = (oldPwd: string, newPwd: string) =>{
    // return request({
    //     url:'/sessions/register',
    //     method:'POST',
    //     data:user
    // })
    return new Promise(resolve => {
        setTimeout(() => {
            if (oldPwd === '123') {
                resolve({
                    status: 200,
                    message: '修改成功'
                })
            } else {
                resolve({
                    status: 400,
                    message: '原始密码有误'
                })
            }
        }, 1000)
    })
}


// /**
//  * 保存居民信息
//  * @param user 
//  * @returns 
//  */
//  export const he = user =>{
//     return request({
//         url:'/patients',
//         method:'POST',
//         data:user
//     })
// }
